//
//  yxpShakeVC.m
//  TestProject
//
//  Created by 杨小平 on 14-8-19.
//  Copyright (c) 2014年 yangxiaoping. All rights reserved.
//

#import "yxpShakeVC.h"
#import <AudioToolbox/AudioToolbox.h>

@interface yxpShakeVC ()<UIAlertViewDelegate>
{
     SystemSoundID sound;//系统声音的id 取值范围为：1000-2000
}
@end

@implementation yxpShakeVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)initSystemShake
{
    sound = kSystemSoundID_Vibrate;//震动
}

- (void)play
{
    AudioServicesPlaySystemSound(sound);
}

//成为第一响应者
- (BOOL)canBecomeFirstResponder
{
    return YES;// default is NO
}
//开始摇动
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    [self play];
}
//结束摇动
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    
}
//传感器取消
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    NSLog(@"取消");
}


- (void)viewDidLoad
{
    [super viewDidLoad];
	
    [self initSystemShake];
    
    UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 0)];
    label.text=@"   摇动手机手机就会震动！！！ \n    很简单只需要重写下列方法：ViewController的canBecomeFirstResponder并返回yes\n    motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event这个方法是开始摇动的方法\n  motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event方法是摇动结束调用的方法\n motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event，这个方法是在传感器取消时调用";
    [Tool resizeLabelByContent:label];
    label.textColor=[UIColor skyBlueColor];
    label.center=self.view.center;
    [self.view addSubview:label];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
